package org.bbb.library1.editors;

import org.bbb.library1.model.Book;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IPersistableElement;

//import com.finalist.rcp.core.Book;

/**
 * @author Rob Schellhorn
 */
public class BookEditorInput extends PlatformObject implements IEditorInput {

   private final Book book;

   public BookEditorInput(Book book) {
      if (book == null) throw new IllegalArgumentException();

      this.book = book;
   }

   /*
    * @see java.lang.Object#equals(java.lang.Object)
    */
   @Override
   public boolean equals(Object obj) {
      if (this == obj) return true;

      if (obj instanceof BookEditorInput) {
         return book.equals(BookEditorInput.class.cast(obj).book);
      }

      return false;
   }

   /*
    * @see org.eclipse.ui.IEditorInput#exists()
    */
   public boolean exists() {
      return false;
   }

   public Book getBook() {
      return book;
   }

   /*
    * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
    */
   public ImageDescriptor getImageDescriptor() {
      return null;
   }

   /*
    * @see org.eclipse.ui.IEditorInput#getName()
    */
   public String getName() {
      return book.getTitle();
   }
   
   public String getAname() {
	      return book.getAuthor();
	   }
   

   /*
    * @see org.eclipse.ui.IEditorInput#getPersistable()
    */
   public IPersistableElement getPersistable() {
      return null;
   }

   /*
    * @see org.eclipse.ui.IEditorInput#getToolTipText()
    */
   public String getToolTipText() {
      return getName();
   }

   /*
    * @see java.lang.Object#hashCode()
    */
   @Override
   public int hashCode() {
      return 31 + (book == null ? 0 : book.hashCode());
   }
}
